
#f = open('C:/Documents and Settings/wang322/Desktop/1.prm','r')
filePath = 'C:/_DATA/migration_census_2000/metropolitan/'
f = open(filePath + 'metro_county_fips_2003 - Copy.txt','r')
line = f.readline()

metro = []
county = []

while line:
    #print len(line)
    if len(line) > 1:
        if line[17] <> ' ':
            # county row
            stateFIPS = line[16:18]
            if stateFIPS <> '72' and stateFIPS <> '15' and stateFIPS <> '02':
                # eliminate PR and HI
                countyFIPS = line[16:21]
                metroID = line[:5]            
                county.append([countyFIPS, metroID])
        else:
            # metro row
            metroID = line[:5]
            if line[25] <> ' ':
                metroName = line[24:-31]
                metroType = line[-30:-1]
            #else:
                #metroName = line[27:-23]
                #metroType = line[-22:-1]
                metro.append([metroID, metroName, metroType])
    line = f.readline()
f.close()



fileLoc = filePath + 'metro_county_list.csv'
np.savetxt(fileLoc, county, delimiter=',', fmt = '%s')

fileLoc = filePath + 'metro_list.csv'
#np.savetxt(fileLoc, metro, delimiter=',', fmt = '%s')

#print county
#print len(metro)

print "Done!"